**************************************************************************************************
*** This do file creates the replication results for 
*** Does the California effect operate across borders? Trading- and investing-up in automobile emission standards 							 	*/
*** Richard Perkins (LSE)																		*/
*** Eric Neumayer (LSE)																			*/
*** 																							*/
*** Published in: Journal of European Public Policy, 19 (2), 2012, pp. 217-237														*/
**************************************************************************************************
**************************************************************************************************
/* Note: 
You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 													*/
**************************************************************************************************

version 11.0
drop _all
clear matrix
clear mata
set mem 800m
set mat 5000

capture net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o)			/* checks whether outreg2 is installed 		*/

***********************************************************************************
local DIR = "C:\Research\Patents\Patstat\"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************

use "Article for JEPP cross-section (automobile).dta", clear

** Descriptive stats
quietly ologit   auto_emissions_reg     spatial_lag_variable lnfdisectoral_vehicles    lngdppcconst   lnpassengercars  if inc_highoecd==0 &  eu27dum==0, robust
su  auto_emissions_reg    spatial_lag_variable lnfdisectoral_vehicles    lngdppcconst   lnpassengercars urban trade fdiinstocktogdp if e(sample)
corr  auto_emissions_reg     spatial_lag_variable lnfdisectoral_vehicles    lngdppcconst   lnpassengercars urban trade fdiinstocktogdp if e(sample)

** table 2
* model 1
ologit   auto_emissions_reg     spatial_lag_variable lnfdisectoral_vehicles    lngdppcconst   if inc_highoecd==0 &  eu27dum==0, robust
outreg2 using table1, replace excel

* model 2
ologit   auto_emissions_reg     spatial_lag_variable lnfdisectoral_vehicles    lngdppcconst   lnpassengercars  if inc_highoecd==0 &  eu27dum==0, robust
outreg2 using table1, append excel

* model 3
ologit   auto_emissions_reg     spatial_lag_variable lnfdisectoral_vehicles    lngdppcconst   lnpassengercars urban if inc_highoecd==0 &  eu27dum==0, robust
outreg2 using table1, append excel

* model 4
ologit   auto_emissions_reg     spatial_lag_variable lnfdisectoral_vehicles    lngdppcconst   lnpassengercars urban trade fdiinstocktogdp if inc_highoecd==0 &  eu27dum==0, robust
outreg2 using table1, append excel



use "Article for JEPP panel (automobile).dta", clear

tsset countryid year

preserve
drop if year==2009

** table 3: Fixed effects estimation results
* model 1
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst i.year if inc_highoecd==0 &  eu27dum==0, fe  robust 
outreg2 using table2, replace excel

* model 2
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst   l.lnpassengercars  i.year if inc_highoecd==0 &  eu27dum==0, fe  robust 
outreg2 using table2, append excel

* model 3
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst   l.lnpassengercars l.urban i.year if inc_highoecd==0 &  eu27dum==0, fe  robust 
outreg2 using table2, append excel

* model 4
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst   l.lnpassengercars l.urban l.trade l.fdiinstocktogdp  i.year if inc_highoecd==0 &  eu27dum==0, fe  robust 
outreg2 using table2, append excel

* Robustness test: Random effects estimation results
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst i.year if inc_highoecd==0 &  eu27dum==0, re  robust cluster(country)
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst   l.lnpassengercars  i.year if inc_highoecd==0 &  eu27dum==0, re  robust cluster(country)
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst   l.lnpassengercars l.urban i.year if inc_highoecd==0 &  eu27dum==0, re  robust cluster(country)
xi: xtreg  auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst  l.urban  l.lnpassengercars l.trade l.fdiinstocktogdp  i.year if inc_highoecd==0 &  eu27dum==0, re  robust cluster(country)

* Robustness test: Fixed effects and LDV estimation results
xi: xtreg  auto_emissions_reg l.auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst i.year if inc_highoecd==0 &  eu27dum==0, fe  robust
xi: xtreg  auto_emissions_reg l.auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst l.lnpassengercars   i.year if inc_highoecd==0 &  eu27dum==0, fe  robust
xi: xtreg  auto_emissions_reg l.auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst   l.lnpassengercars l.urban i.year if inc_highoecd==0 &  eu27dum==0, fe  robust 
xi: xtreg  auto_emissions_reg l.auto_emissions_reg l.spatial_lag_variable   l.lnfdisectoral_vehicles  l.lngdppcconst l.lnpassengercars l.urban l.trade l.fdiinstocktogdp    i.year if inc_highoecd==0 &  eu27dum==0, fe  robust



restore

